package com.github.toucan;

import org.springframework.shell.component.view.control.StatusBarView;
import org.springframework.shell.component.view.event.KeyEvent;

import java.util.List;

public class StatusBarExample {
    public static void main(String[] args) {
        // 创建状态项
        StatusBarView.StatusItem item1 = new StatusBarView.StatusItem("文件");
        StatusBarView.StatusItem item2 = new StatusBarView.StatusItem("编辑");

        // 为第三个项创建动作
        Runnable saveAction = () -> System.out.println("保存操作被执行");
        StatusBarView.StatusItem item3 = new StatusBarView.StatusItem("保存", saveAction);

        // 创建状态栏并添加项
        StatusBarView statusBar = new StatusBarView(List.of(item1, item2, item3));

        // 或者使用数组形式的构造函数
        // StatusBarView statusBar2 = new StatusBarView(new StatusBarView.StatusItem[] {
        //     StatusBarView.StatusItem.of("文件"),
        //     StatusBarView.StatusItem.of("编辑"),
        //     StatusBarView.StatusItem.of("保存", saveAction)
        // });

        // 添加热键支持
        StatusBarView.StatusItem itemWithHotkey = StatusBarView.StatusItem.of(
            "帮助",
            () -> System.out.println("帮助文档打开"),
            KeyEvent.Key.f1
        );

        StatusBarView statusBarWithHotkey = new StatusBarView();
        statusBarWithHotkey.setItems(List.of(itemWithHotkey));

        System.out.println(itemWithHotkey.toString());

    }
}